<template>
  <div>
    <h2>添 加 小 班</h2>
    <div class="add">
      <div class="left">
        <el-form :label-position="labelPosition" label-width="90px">
          <el-form-item label="名称">
            <el-input v-model="className"></el-input>
          </el-form-item>
          <el-form-item label="负责人电话">
            <el-input v-model="classPhone"></el-input>
          </el-form-item>
          <el-form-item label="负责区域">
            <el-select v-model="value" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.areaId"
                :label="item.areaName"
                :value="item.areaId"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>

      <div>
        <el-form :label-position="labelPosition" label-width="80px">
          <el-form-item label="负责人">
            <el-input v-model="classManager"></el-input>
          </el-form-item>
          <el-form-item label="人员数量">
            <el-input v-model="classNum"></el-input>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <el-row>
      <el-button plain @click="addClass()">添加</el-button>
    </el-row>
  </div>
</template>

<script>
export default {
  data() {
    return {
      className: "",
      classManager: "",
      classPhone: "",
      classNum: "",
      labelPosition: "left",
      options: [],
      value: "",
      areaId: "",
    };
  },
  methods: {
    async getArea() {
      let paramObj = {};
      let info = await this.ajax.getSubmit("/api/area/result", paramObj);
      //console.log(info);
      this.options = info;
      //console.log(this.options);
    },
    async addClass() {
      this.areaId = this.value + "";
      let paramObj = {
        className: this.className,
        classManager: this.classManager,
        classPhone: this.classPhone,
        classNum: this.classNum,
        areaId: this.areaId,
      };
      let info = await this.ajax.getSubmit("/api/class/add", paramObj);
      console.log(info);

      this.className = "";
      this.classManager = "";
      this.classPhone = "";
      this.classNum = "";
      this.areaId = "";
    },
  },
  created() {
    this.getArea();
  },
};
</script>

<style>
</style>